package elasticsearchDemo.demo;
/**
 *  建立链接
 * @author Shensg
 * 
 * 2018年10月8日
 */

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Demo_1 {
	private Logger logger = LoggerFactory.getLogger(Demo_1.class);
	
	public static String host = "127.0.0.1";
	
	public static int port = 9300;//http请求的端口是9200，客户端是9300
	
	@Test
	public void testConnect() throws UnknownHostException {
		//创建客户端
		TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
				.addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
		logger.info("ElasticSearch connect info:"+client.toString());
		//关闭客户端
		//System.out.println(client.toString());
		client.close();
	}
}
